You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recursively cloning objects on each call could impact performance for large or deeply nested payloads; consider in-place sanitization or limiting recursion depth.
-const sanitizeBody = (body: any): any => {- if (!body) return body;+const sanitizeBody = (body: any, seen = new WeakSet<any>()): any => {+ if (body === null || typeof body !== "object") return body;+ if (seen.has(body)) return "[Circular]";+ seen.add(body);
Suggestion importance[1-10]: 8
__
Why: Introducing cycle detection with a WeakSet avoids infinite recursion on circular objects, preventing potential crashes in sanitizeBody.
Medium
Handle arrays in sanitization
Add explicit handling for arrays so that lists are properly traversed and returned as arrays rather than being spread into objects. This prevents unexpected type changes when sanitizing array payloads.
const sanitizeBody = (body: any): any => {
- if (!body) return body;+ if (body === null || typeof body !== "object") return body;+ if (Array.isArray(body)) return body.map(sanitizeBody);
Suggestion importance[1-10]: 7
__
Why: Adding array support in sanitizeBody prevents improper object spreading and ensures lists are sanitized correctly, improving robustness.
Medium
Refine sensitive-field matching
Prevent over-matching by changing substring checks to match exact field names or common suffix patterns. This reduces false positives (e.g. fields like "monkey").
Why: Applying sanitizeBody to req.headers and req.cookies prevents leaking tokens and session data in logs, which is a significant security improvement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Introduce helper to redact sensitive request fields
Define sensitiveFields list for masking in logs
Recursively sanitize nested objects in request body
Use sanitized body in logging middleware
Changes walkthrough 📝
server.ts
Add request body sanitization for loggingfunctions/src/server.ts
sanitizeBodyfunction to mask sensitive fieldssensitiveFieldslist for redactionsanitizeBody